package cn.intellijboy.gradle.plugin.task;

import cn.intellijboy.gradle.plugin.model.ConfigurationModel;
import cn.intellijboy.gradle.plugin.model.ConfigurationType;
import cn.intellijboy.gradle.plugin.model.GradleBuildModel;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import lombok.Getter;
import lombok.Setter;
import org.gradle.api.DefaultTask;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.LibraryBinaryIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
import org.gradle.api.artifacts.result.DependencyResult;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.diagnostics.internal.ConfigurationDetails;
import org.gradle.api.tasks.diagnostics.internal.ProjectDetails;
import org.gradle.api.tasks.options.Option;
import org.gradle.internal.serialization.Cached;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 配置解析任务
 * 获取所有或指定的配置对象
 * <p>
 * 任务名称：analyzeConfiguration
 * 任务分组：xingzhe
 * 任务入参：--configuration=[compileClasspath, runtimeClasspath]
 * 任务出参：--output=[console,file location]
 * <p>
 * 注意：配置解析需要在配置阶段执行
 */
public class AnalyzeConfigurationTask extends AbstractDependencyAnalyzeTask {

    @TaskAction
    public void analyze() {
        // 获取所有配置对象
        List<ConfigurationModel> configurationModels = initConfigurationModels();
        // 打印结果
        jsonLogPrint(configurationModels);
    }

}

